package com.controller;

import com.Constants;
import com.model.PageResponseObject;
import com.model.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


/**
 * author 张新林
 * 时间 2019/1/20 18:14
 * 描述
 */
@RestController
@RequestMapping(value="/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取全部User列表
     * @return
     * @throws IOException
     */
    @RequestMapping(value="/", method=RequestMethod.GET)
    public PageResponseObject view() throws IOException {

        int start = 0;
        PageResponseObject result = new PageResponseObject();

        List<User> list = userService.findUser();
        result.setResultObject(list);

        return result;
    }

    /**
     * 分页获取User列表
     * @return
     * @throws IOException
     */
    @RequestMapping(value="/viewByPage", method=RequestMethod.GET)
    public PageResponseObject viewByPage() throws IOException {

        int start = 0;
        PageResponseObject result = new PageResponseObject();

        List<User> list = userService.findUserPage(start, Constants.PAGE_SIZE);
        result.setResultObject(list);

        return result;
    }
}
